﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Data.OleDb;
using DAO;

/// <summary>
/// Summary description for manufacturerDAO
/// </summary>
public class manufacturerDAO
{
	public manufacturerDAO()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    #region lay thong tin
    public static DataTable GetListOfCompanies()
    {
        string sQuery = "select * from Company";
        SqlConnection con = DataProvider.TaoKetNoi();
        DataTable dt = DataProvider.LayDataTable(sQuery, con);
        DataProvider.DongKetNoi(con);
        return dt;
    }
    public static bool ktraTonTai(manufacturerDTO mDTO)
    {
        string sQuery = "select * from Company where CompanyCode='" + mDTO.CompanyCode + "'";
        SqlConnection con = DataProvider.TaoKetNoi();
        DataTable dt = DataProvider.LayDataTable(sQuery, con);
        DataProvider.DongKetNoi(con);
        if (dt.Rows.Count > 0)
        {
            return true;
        }
        return false;
    }
    #endregion
    #region them thong tin
    public static void EditInfo(manufacturerDTO mDTO)
    {
        string sQuery = "update Company set CompanyName = '" + mDTO.CompanyName + "',Logo ='" + mDTO.Logo + "' where CompanyCode = '" + mDTO.CompanyCode + "'";
        SqlConnection con = DataProvider.TaoKetNoi();
        DataProvider.ExecuteNonQuery(sQuery, con);
        DataProvider.DongKetNoi(con);
    }
    public static void DeleteCompany(manufacturerDTO mDTO)
    {
        string sQuery = "delete from Company where CompanyCode ='" + mDTO.CompanyCode + "'";
        SqlConnection con = DataProvider.TaoKetNoi();
        DataProvider.ExecuteNonQuery(sQuery, con);
        DataProvider.DongKetNoi(con);
    }
    public static void AddCompany(manufacturerDTO mDTO)
    {
        string sQuery = "insert into Company(CompanyCode,CompanyName,Logo) values('" + mDTO.CompanyCode + "','" + mDTO.CompanyName + "','" + mDTO.Logo + "')";
        SqlConnection con = DataProvider.TaoKetNoi();
        DataProvider.ExecuteNonQuery(sQuery, con);
        DataProvider.DongKetNoi(con);
    }
    #endregion
}